from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status

from artmarket.models import Order


class CardStatisticsView(APIView):
    # 统计出订单待支付数量，已完成数量，退货中数量
    def get(self, request):
        # 获取订单表中的待支付，已完成，退货中数量
        order_pending__count = Order.objects.filter(status=Order.ORDER_PENDING).count()
        order_completed__count = Order.objects.filter(status=Order.ORDER_COMPLETED).count()
        return_requested__count = Order.objects.filter(status=Order.ORDER_RETURN_REQUESTED).count()
        response_data = []
        response_data.append(
            {
                'order_pending__count': order_pending__count,
                'order_completed__count': order_completed__count,
                'return_requested__count': return_requested__count
            }
        )
        # 返回统计结果
        return Response(data={'data': response_data}, status=status.HTTP_200_OK)
